package com.sunrise.xdoc.entity.employee;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Type;
import org.joda.time.YearMonth;

import com.sunrise.xdoc.entity.AbstractAuditEntity;
import com.sunrise.xdoc.entity.contact.NhanVien;
import com.sunrise.xdoc.entity.finance.PhieuThanhToan;

@Entity
@Table(name = "emp_tra_luong")
@Inheritance(strategy = InheritanceType.JOINED)
public class TraLuong extends AbstractAuditEntity {
	private static final long serialVersionUID = -7753066340659811908L;
	private NhanVien nhanVien;
	private LoaiTraLuong loai;
	private YearMonth yearMonth;
	private PhieuThanhToan phieuThanhToan;

	public static enum LoaiTraLuong {
		TAM_UNG, TAT_TOAN
	}

	@ManyToOne
	@JoinColumn(name = "nhan_Vien_id")
	@NotNull
	public NhanVien getNhanVien() {
		return nhanVien;
	}

	public void setNhanVien(NhanVien nhanVien) {
		this.nhanVien = nhanVien;
	}

	@Column(name = "loai")
	@NotNull
	@Enumerated(EnumType.STRING)
	public LoaiTraLuong getLoai() {
		return loai;
	}

	public void setLoai(LoaiTraLuong loai) {
		this.loai = loai;
	}

	@Column(name = "month", nullable = false)
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentYearMonthAsString")
	public YearMonth getYearMonth() {
		return yearMonth;
	}

	public void setYearMonth(YearMonth yearMonth) {
		this.yearMonth = yearMonth;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "phieu_thanh_toan")
	@NotNull
	public PhieuThanhToan getPhieuThanhToan() {
		return phieuThanhToan;
	}

	public void setPhieuThanhToan(PhieuThanhToan phieuThanhToan) {
		this.phieuThanhToan = phieuThanhToan;
	}
}
